package com.ruoyi.business.service.impl;

import com.ruoyi.business.mapper.DashboardMapper;
import com.ruoyi.business.service.IDashboardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class DashboardServiceImpl implements IDashboardService {

    @Autowired
    private DashboardMapper dashboardMapper;

    @Override
    // TODO: 后续可以为此方法添加 @Cacheable 缓存
    public Map<String, Object> getPartnerDashboardData(Long partnerId) {
        Map<String, Object> data = new HashMap<>();
        data.put("incomeToday", dashboardMapper.sumPartnerIncomeToday(partnerId));
        data.put("incomeTotal", dashboardMapper.sumPartnerIncomeTotal(partnerId));
        data.put("deviceCount", dashboardMapper.countPartnerDevices(partnerId));
        data.put("deviceOnlineCount", dashboardMapper.countPartnerOnlineDevices(partnerId));
        return data;
    }

    @Override
    // TODO: 后续可以为此方法添加 @Cacheable 缓存
    public Map<String, Object> getDistributorDashboardData(Long distributorId) {
        Map<String, Object> data = new HashMap<>();
        data.put("salesToday", dashboardMapper.sumDistributorSalesToday(distributorId));
        data.put("incomeTotal", dashboardMapper.sumDistributorIncomeTotal(distributorId));
        data.put("partnerCount", dashboardMapper.countDistributorPartners(distributorId));
        data.put("deviceCount", dashboardMapper.countDistributorDevices(distributorId));
        return data;
    }
}